<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人中心</title>
    <link rel="stylesheet" href="{{ url_for('static',filename='layui/css/layui.css') }}">
    <script type="text/javascript" src="{{ url_for('static',filename='jquery/jquery-3.5.1.min.js') }}"></script>
    <script type="text/javascript">
        //数据更新
        function UpdateUser() {
            uname = $("#uname").val();
            if (uname.length == 0) {
                layer.msg("用户名不能为空",{icon:2})
                return
            }
            upwd = $("#upwd").val();
            if (upwd.length == 0) {
                layer.msg("密码不能为空",{icon:2})
                return
            }
            if (upwd.length <6) {
                layer.msg("密码不能少于6位",{icon:2})
                return
            }
            cupwd=$("#cupwd").val();
            if(upwd!=cupwd){
                layer.msg("确认密码不对",{icon:2})
                return
            }
            $.ajax({
                url: "UpdateUser",
                method: "post",
                data: $("#update").serialize(),
                success: function (result) {
                    if (result == "1")
                        layer.msg("修改成功", {
                            time: 1000,
                            icon: 1
                        }, function () {
                            window.location.href = "/user"
                        });

                    else
                        alert("修改失败")
                },
                error: function (e) {
                    alert("连接失败")
                }

            });
        }
        //地址
        function Useraddress() {
            $.ajax({
                url: "Useraddress",
                method: "post",
                data: $("#address").serialize(),
                success: function (result) {
                    if (result == "1")
                        layer.msg("修改成功", {
                            time: 1000,
                            icon: 1
                        }, function () {
                            window.location.href = "/user"
                        });

                    else
                        alert("修改失败")
                },
                error: function (e) {
                    alert("连接失败")
                }

            });
        }
        //信息
        $(function() {
            $.ajax({
                url:"getPersonal",
                method:"get",
                success:function(result) {
                    {# json字符串改json对象 #}
                    jsonObj=JSON.parse(result);
                    var s="";
                    {#  str+="<tr><tb>"+result[0][1]+"</tb><tb>"+JSON.parse(result[0][3])+"</tb><tb>"+result[0][4]+"</tb><tb>"+result[0][5]+"</tb><tb>"+result[1][0]+"</tb></tr>"#}
                    $.each(jsonObj,function(index,row) {
                        if(index=="0")
                            s+="<tr><th>"+row[1]+"</th><th>"+row[3]+"</th><th>"+row[4]+"</th><th>"+row[5]+"</th>"
                        else
                            s+="<th>"+row[0]+"</th></tr>"
                    });

                    $("#body").html(s);
                },
                error:function (e) {
                    layer.msg("连接失败", {
                        time: 1000,
                        icon: 2
                    });
                }
            });
        });
    </script>
</head>
<body>
<div class="layui-elem-quote">
    个人中心
</div>
<br>
<hr class="layui-border-orange">
<br>
<div >
    <table class="layui-table">
        <tr>
            <th>用户名</th>
            <th>性别</th>
            <th>邮箱</th>
            <th>手机</th>
            <th>地址</th>
        </tr>
        <tbody id="body">

        </tbody>
    </table>
</div>
<br>
<hr class="layui-border-orange">
<br>
<div class="layui-elem-quote">
    修改信息
</div>
<br>
<hr class="layui-border-orange">
<br>
<form method="post" id="update" name="update" class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名*</label>
        <div class="layui-input-block" style="margin-right: 20px">
            <input id="uname" name="uname" class="layui-input" placeholder="请输入用户名">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码*</label>
        <div class="layui-input-block" style="margin-right: 20px">
            <input type="password" id="upwd" name="upwd" class="layui-input" placeholder="请输入密码">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码*</label>
        <div class="layui-input-block" style="margin-right: 20px">
            <input type="password" id="cupwd" name="cupwd" class="layui-input" placeholder="请输入确认密码">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="男" title="男" checked="">
            <input type="radio" name="sex" value="女" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block" style="margin-right: 20px">
            <input type="email" id="email" name="email" class="layui-input" placeholder="请输入邮箱">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block" style="margin-right: 20px">
            <input type="text" id="phone" name="phone" class="layui-input" placeholder="请输入手机号">
        </div>
    </div>
    <div class="layui-form-item" align="center">
        <a href="javascript:UpdateUser()" class="layui-btn"><span
                class="layui-icon layui-icon-edit"></span> 修改</a>
        <a href="javascript:update.reset()" class="layui-btn layui-btn-warm"><span
                class="layui-icon layui-icon-fonts-clear"></span> 重置</a>
    </div>
</form>
<br>
<hr class="layui-border-orange">
<br>
<div class="layui-elem-quote">
    修改地址
</div>
<br>
<hr class="layui-border-orange">
<br>
<form method="post" id="address" name="address" class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-block" style="margin-right: 20px">
            <input type="text" id="uaddress" name="uaddress" class="layui-input" placeholder="请输入地址">
        </div>
    </div>
    <div class="layui-form-item" align="center">
        <a href="javascript:Useraddress()" class="layui-btn"><span
                class="layui-icon layui-icon-edit"></span> 修改</a>
        <a href="javascript:address.reset()" class="layui-btn layui-btn-warm"><span
                class="layui-icon layui-icon-fonts-clear"></span> 重置</a>
    </div>
</form>




<script src="{{ url_for('static',filename='layui/layui.js') }}"></script>
<script>
    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;

    });
</script>
</body>
</html>